package com.adpython.utils;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtil {
	
	private String mailAccount;
	private String fromName;
	
	public boolean sendMail(String toMailAddress,String toName, String subject, String messageText){
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		try{
			Message msg=new MimeMessage(session);
			msg.setFrom(new InternetAddress(mailAccount,fromName));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toMailAddress,toName));
			msg.setSubject(subject);
			msg.setText(messageText);
			Transport.send(msg);
		}catch(MessagingException me){
			return false;
		}catch(UnsupportedEncodingException uee){
			return false;
		}
		return true;
	}

	public void setMailAccount(String mailAccount){
		this.mailAccount=mailAccount;
	}
	public String getMailAccount(){
		return this.mailAccount;
	}
	
	public void setFromName(String fromName){
		this.fromName=fromName;
	}
	public String getFromName(){
		return this.fromName;
	}
	
}